package com.mall.service.order.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mall.commons.common.CommonResult;
import com.mall.model.domain.OmsOrder;
import com.mall.model.domain.OmsOrderItem;
import com.mall.model.dto.DeliveryParamList;
import com.mall.model.dto.MoneyInfoParam;
import com.mall.model.dto.OrderAllDto;
import com.mall.model.dto.ReceiverInfoParam;
import com.mall.model.vo.OrderAllVo;
import com.mall.model.vo.OrderInfo;
import com.mall.model.vo.PageResult;
import com.mall.service.order.service.OmsOrderItemService;
import com.mall.service.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.integration.IntegrationDataSourceInitializer;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/order")
public class OmsOrderController {
    @Autowired
    private OrderService orderService;


    //批量删除订单
    @PostMapping("/delete")
    public CommonResult deleteOrder(@RequestParam List<Integer> ids) {
          orderService.deleteByIds(ids);
        return CommonResult.success("删除成功");
    }

    //查询订单
    @GetMapping("/list")
    public CommonResult select( Integer pageNum, Integer pageSize,String createTime, String orderSn, Integer orderType, String receiverKeyword, Integer sourceType, Integer status) {
        PageResult pageResult = orderService.pageList(pageNum, pageSize, createTime, orderSn, orderType, receiverKeyword, sourceType, status);
        return CommonResult.success(pageResult);
    }

    //批量关闭订单
    @PostMapping("/update/close")
    public CommonResult update( @RequestParam List<Integer> ids, @RequestParam String note) {
        orderService.updateByIds(ids, note);
        return CommonResult.success("关闭成功");
    }

    //批量发货
    @PostMapping("/update/delivery")
    public CommonResult updateDe(@RequestBody List<DeliveryParamList> list) {
        orderService.updateByDe(list);
        return CommonResult.success("发货成功");
    }

    //管理员后台修改订单费用信息
    @PostMapping("/update/moneyInfo")
    public CommonResult updateMo(@RequestBody  MoneyInfoParam list) {
        orderService.updateMo(list);
        return CommonResult.success("修改成功");
    }
    //备注订单信息
    @PostMapping("/update/note")
    public CommonResult updateNt(@RequestParam Integer id,@RequestParam String note,@RequestParam Integer status) {
        orderService.updateNt(id,note,status);
        return CommonResult.success("备注成功");
    }
    //修改收货人信息
    @PostMapping("/update/receiverInfo")
    public CommonResult updateInfo(@RequestBody ReceiverInfoParam receiverInfoParam){
        orderService.updateInfo(receiverInfoParam);
        return CommonResult.success("修改成功");
    }
    //查看订单信息
    @GetMapping("/{id}")
    public CommonResult selectInfo(@PathVariable Integer id){
       OrderInfo orderInfo=orderService.selectInfo(id);
       return CommonResult.success(orderInfo);
    }
}
